OPTIONAL SDL SDL Binding for SwiftForth.
{ Notes

To do:
 SDL_image
 SDL_net
 pixel format macros - though maybe not needed
 complete surfaces , including structures
 rwops structure
 complete window management
 threads
 video

Several functions that are only available in 1.3 are commented out.

}

include ..\DLL-TOOLS

Only Forth Definitions

Library SDL.DLL

Cfunction: SDL_Linked_Version ( -- addr )
Cfunction: SDL_ListModes ( pixelformat flags -- addr )

1        CIMPORT: SDL_Init
1        CIMPORT: SDL_InitSubSystem
0 VOID   CIMPORT: SDL_Quit
1 VOID   CIMPORT: SDL_QuitSubSystem
0        CIMPORT: SDL_GetError

\ http://www.libsdl.org/cgi/docwiki.cgi/SDL_Video
4        CIMPORT: SDL_SetVideoMode
0        CIMPORT: SDL_GetVideoInfo
0        CIMPORT: SDL_GetVideoSurface
0 VOID   CIMPORT: SDL_GL_SwapBuffers
1 VOID   CIMPORT: SDL_Flip
8        CIMPORT: SDL_CreateRGBSurface
9        CIMPORT: SDL_CreateRGBSurfaceFrom \ (void *Pixels, int width, int height, int bitsPerpixel, int ppitch,
                                           \  Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
1 VOID   CIMPORT: SDL_FreeSurface
4        CIMPORT: SDL_MapRGB
4 VOID   CIMPORT: SDL_UpperBlit
3 VOID   CIMPORT: SDL_FillRect
3 VOID   CIMPORT: SDL_SetColorKey
3 VOID   CIMPORT: SDL_SetAlpha
3 VOID   CIMPORT: SDL_SetGammaRamp
5 VOID   CIMPORT: SDL_GetRGB
6 VOID   CIMPORT: SDL_GetRGBA  \ (Uint32 pixel, SDL_pixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
5        CIMPORT: SDL_MapRGBA  \ (SDL_pixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
4        CIMPORT: SDL_MapRGB   \ (SDL_pixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b);
2 VOID   CIMPORT: SDL_GL_SetAttribute

4 VOID   CIMPORT: SDL_UpperBlit \ (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);

\ http://www.libsdl.org/cgi/docwiki.cgi/SDL_Window_Management
1 VOID   CIMPORT: SDL_WM_ToggleFullScreen
1 VOID   CIMPORT: SDL_WM_GrabInput

\ http://www.libsdl.org/cgi/docwiki.cgi/SDL_Events
1        CIMPORT: SDL_PollEvent
1        CIMPORT: SDL_WaitEvent
\ 1        CIMPORT: SDL_HasEvent
1        CIMPORT: SDL_PushEvent
2        cimport: SDL_EventState   \ Uint8 SDL_EventState(Uint8 type, int state);

\ 0        cimport: SDL_GetNumKeyboards \ (void)
\ Function: SDL_SelectKeyboard ( n -- n ) \ int SDL_SelectKeyboard (int index)
\ Function: SDL_GetKeyboardState ( int-*numkeys -- addr ) \ Uint8 *SDL_GetKeyboardState (int *numkeys)
Function: SDL_GetModState ( -- SDLMod ) \ SDLMod SDL_GetModState (void)
Function: SDL_SetModState ( SDLMod -- ) \ void SDL_SetModState (SDLMod modstate)
\ Function: SDL_GetKeyFromScancode ( SDLscancode -- SDLkey ) \ SDLKey SDL_GetKeyFromScancode (SDL_scancode scancode)
\ Function: SDL_GetScancodeFromKey ( SDLKey -- SDL_scancode ) \ SDL_scancode SDL_GetScancodeFromKey (SDLKey key)
\ Function: SDL_GetScancodeName ( SDLscancode -- addr ) \ const char *SDL_GetScancodeName (SDL_scancode scancode)
Function: SDL_GetKeyName  ( SDLKey -- addr ) \ const char *SDL_GetKeyName (SDLKey key)


\ Function: SDL_GetNumMice ( -- n )
\ Function: SDL_GetMouseName ( val -- addr )
\ Function: SDL_SelectMouse ( n -- n )
\ Function: SDL_GetMouseFocusWindow ( -- SDL_windowID )
\ Function: SDL_SetRelativeMouseMode  ( boolean -- n )
\ Function: SDL_GetRelativeMouseMode  ( -- boolean )
\ Function: SDL_WarpMouseInWindow ( SDL_WindowID x y -- )
\ Function: SDL_CreateCursor (Uint8-*data, Uint8-*mask  w h hotx hoty -- SDL_Cursor )
\ Function: SDL_SetCursor ( SDL_cursor -- )
\ Function: SDL_GetCursor ( -- SDL_cursor )
\ Function: SDL_FreeCursor ( SDL_Cursor -- )
\ Function: SDL_GetCursorsNumber ( index -- n )
\ Function: SDL_GetCurrentCursor ( index -- n )
0 VOID   CIMPORT: SDL_PumpEvents
2 VOID   CIMPORT: SDL_EventState
2 VOID   CIMPORT: SDL_EnableKeyRepeat ( delay interval -- )
1        CIMPORT: SDL_GetKeyState
2        CIMPORT: SDL_GetMouseState   ( *x *y -- buttonmask )
2        cimport: SDL_GetRelativeMouseState ( *x *y -- buttonmask )
2 VOID   CIMPORT: SDL_WarpMouse
1 VOID   CIMPORT: SDL_ShowCursor

1        CIMPORT: SDL_JoystickOpen   ( n -- 'joystick )
1 VOID   CIMPORT: SDL_JoystickEventState
2        CIMPORT: SDL_JoystickGetAxis
2        CIMPORT: SDL_JoystickGetHat
2        CIMPORT: SDL_JoystickGetButton
0        cimport: SDL_NumJoysticks \ extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
1        cimport: SDL_JoystickName \ extern DECLSPEC const char *SDLCALL SDL_JoystickName(int device_index);
1        cimport: SDL_JoystickOpened \ extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
1        cimport: SDL_JoystickIndex \ extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick * joystick);
1        cimport: SDL_JoystickNumAxes \ extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
1 void   cimport: SDL_JoystickUpdate \ extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
1 void   cimport: SDL_JoystickClose \ extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);

0        CIMPORT: SDL_GetTicks
1 VOID   cimport: SDL_Delay

\ see sdl_loadso.h
CFunction: SDL_LoadObject ( zaddr -- handle-addr )
CFunction: SDL_LoadFunction ( handle-addr zaddr -- addr )
CFunction: SDL_UnloadObject ( handle-addr -- )


{
: ?sdlerror  1
    SDL_GetError zcount ?dup IF cr ." SDL Error: " type
    ELSE drop drop THEN ;
}

CFunction: SDL_GL_GetProcAddress ( zstring -- addr )
CFunction: SDL_GL_LoadLibrary ( zstring -- flag )
\ 1 IMPORT: SDL_GL_GetProcAddress

\ ---------------
\    Constants
\ ---------------

\ Transparency definitions: These define alpha as the opacity of a surface
#define SDL_ALPHA_OPAQUE 255
#define SDL_ALPHA_TRANSPARENT 0

\ These are the currently supported flags for the SDL_surface
\ Available for SDL_CreateRGBSurface() or SDL_SetVideoMode()
#define SDL_SWSURFACE   $00000000      \ Surface is in system memory
#define SDL_HWSURFACE   $00000001      \ Surface is in video memory
#define SDL_ASYNCBLIT   $00000004      \ Use asynchronous blits if possible
\ Available for SDL_SetVideoMode()
#define SDL_ANYFORMAT   $10000000      \ Allow any video depth/pixel-format
#define SDL_HWPALETTE   $20000000      \ Surface has exclusive palette
#define SDL_DOUBLEBUF   $40000000      \ Set up double-buffered video mode
#define SDL_FULLSCREEN  $80000000      \ Surface is a full screen display
#define SDL_OPENGL      $00000002      \ Create an OpenGL rendering context
#define SDL_OPENGLBLIT  $0000000A      \ Create an OpenGL rendering context and use it for blitting
#define SDL_RESIZABLE   $00000010      \ This video mode may be resized
#define SDL_NOFRAME     $00000020      \ No window caption or edge frame
\ Used internally (read-only)
#define SDL_HWACCEL     $00000100      \ Blit uses hardware acceleration
#define SDL_SRCCOLORKEY $00001000      \ Blit uses a source color key
#define SDL_RLEACCELOK  $00002000      \ Private flag
#define SDL_RLEACCEL    $00004000      \ Surface is RLE encoded
#define SDL_SRCALPHA    $00010000      \ Blit uses source alpha blending
#define SDL_PREALLOC    $01000000      \ Surface uses preallocated memory


\ Public enumeration for setting the OpenGL window attributes.
0
ENUM    SDL_GL_RED_SIZE
ENUM    SDL_GL_GREEN_SIZE
ENUM    SDL_GL_BLUE_SIZE
ENUM    SDL_GL_ALPHA_SIZE
ENUM    SDL_GL_BUFFER_SIZE
ENUM    SDL_GL_DOUBLEBUFFER
ENUM    SDL_GL_DEPTH_SIZE
ENUM    SDL_GL_STENCIL_SIZE
ENUM    SDL_GL_ACCUM_RED_SIZE
ENUM    SDL_GL_ACCUM_GREEN_SIZE
ENUM    SDL_GL_ACCUM_BLUE_SIZE
ENUM    SDL_GL_ACCUM_ALPHA_SIZE
ENUM    SDL_GL_STEREO
ENUM    SDL_GL_MULTISAMPLEBUFFERS
ENUM    SDL_GL_MULTISAMPLESAMPLES
ENUM    SDL_GL_ACCELERATED_VISUAL
ENUM    SDL_GL_SWAP_CONTROL
DROP


\ flags for SDL_SetPalette()
#define SDL_LOGPAL $01
#define SDL_PHYSPAL $02


\ flags for SDL_Init()
#define SDL_INIT_TIMER          $00000001
#define SDL_INIT_AUDIO          $00000010
#define SDL_INIT_VIDEO          $00000020
#define SDL_INIT_CDROM          $00000100
#define SDL_INIT_JOYSTICK       $00000200
#define SDL_INIT_NOPARACHUTE    $00100000      \ Don't catch fatal signals }
#define SDL_INIT_EVENTTHREAD    $01000000      \ Not supported on all OS's }
#define SDL_INIT_EVERYTHING     $0000FFFF


{ 0
ENUM   KMOD_NONE   \ = $0000,
ENUM   KMOD_LSHIFT \ = $0001,
ENUM   KMOD_RSHIFT \ = $0002,
ENUM   KMOD_LCTRL  \ = $0040,
ENUM   KMOD_RCTRL  \ = $0080,
ENUM   KMOD_LALT   \ = $0100,
ENUM   KMOD_RALT   \ = $0200,
ENUM   KMOD_LMETA  \ = $0400,
ENUM   KMOD_RMETA  \ = $0800,
ENUM   KMOD_NUM    \ = $1000,
ENUM   KMOD_CAPS   \ = $2000,
ENUM   KMOD_MODE   \ = $4000,
DROP }

8 CONSTANT SDLK_BACKSPACE    \ 8,
9 CONSTANT SDLK_TAB    \ 9,
12 CONSTANT SDLK_CLEAR     \ 12,
13 CONSTANT SDLK_RETURN    \ 13,
19 CONSTANT SDLK_PAUSE     \ 19,
27 CONSTANT SDLK_ESCAPE    \ 27,
32 ENUM  SDLK_SPACE     \ 32,
ENUM     SDLK_EXCLAIM      \ 33,
ENUM     SDLK_QUOTEDBL     \ 34,
ENUM     SDLK_HASH      \ 35,
ENUM     SDLK_DOLLAR    \ 36,
1 +
ENUM     SDLK_AMPERSAND    \ 38,
ENUM     SDLK_QUOTE     \ 39,
ENUM     SDLK_LEFTPAREN    \ 40,
ENUM     SDLK_RIGHTPAREN      \ 41,
ENUM     SDLK_ASTERISK     \ 42,
ENUM     SDLK_PLUS      \ 43,
ENUM     SDLK_COMMA     \ 44,
ENUM     SDLK_MINUS     \ 45,
ENUM     SDLK_PERIOD    \ 46,
ENUM     SDLK_SLASH     \ 47,
ENUM     SDLK_0         \ 48,
ENUM     SDLK_1         \ 49,
ENUM     SDLK_2         \ 50,
ENUM     SDLK_3         \ 51,
ENUM     SDLK_4         \ 52,
ENUM     SDLK_5         \ 53,
ENUM     SDLK_6         \ 54,
ENUM     SDLK_7         \ 55,
ENUM     SDLK_8         \ 56,
ENUM     SDLK_9         \ 57,
ENUM     SDLK_COLON     \ 58,
ENUM     SDLK_SEMICOLON    \ 59,
ENUM     SDLK_LESS      \ 60,
ENUM     SDLK_EQUALS    \ 61,
ENUM     SDLK_GREATER      \ 62,
ENUM     SDLK_QUESTION     \ 63,
ENUM     SDLK_AT        \ 64,
DROP
   {
      Skip uppercase letters
    }
91
ENUM     SDLK_LEFTBRACKET  \ 91,
ENUM     SDLK_BACKSLASH    \ 92,
ENUM     SDLK_RIGHTBRACKET \ 93,
ENUM     SDLK_CARET     \ 94,
ENUM     SDLK_UNDERSCORE      \ 95,
ENUM     SDLK_BACKQUOTE    \ 96,
ENUM     SDLK_a         \ 97,
ENUM     SDLK_b         \ 98,
ENUM     SDLK_c         \ 99,
ENUM     SDLK_d         \ 100,
ENUM     SDLK_e         \ 101,
ENUM     SDLK_f         \ 102,
ENUM     SDLK_g         \ 103,
ENUM     SDLK_h         \ 104,
ENUM     SDLK_i         \ 105,
ENUM     SDLK_j         \ 106,
ENUM     SDLK_k         \ 107,
ENUM     SDLK_l         \ 108,
ENUM     SDLK_m         \ 109,
ENUM     SDLK_n         \ 110,
ENUM     SDLK_o         \ 111,
ENUM     SDLK_p         \ 112,
ENUM     SDLK_q         \ 113,
ENUM     SDLK_r         \ 114,
ENUM     SDLK_s         \ 115,
ENUM     SDLK_t         \ 116,
ENUM     SDLK_u         \ 117,
ENUM     SDLK_v         \ 118,
ENUM     SDLK_w         \ 119,
ENUM     SDLK_x         \ 120,
ENUM     SDLK_y         \ 121,
ENUM     SDLK_z         \ 122,
DROP
127 CONSTANT SDLK_DELETE    \ 127,
   { End of ASCII mapped keysyms }

   { Numeric keypad }
256
ENUM     SDLK_KP0    \ 256,
ENUM     SDLK_KP1    \ 257,
ENUM     SDLK_KP2    \ 258,
ENUM     SDLK_KP3    \ 259,
ENUM     SDLK_KP4    \ 260,
ENUM     SDLK_KP5    \ 261,
ENUM     SDLK_KP6    \ 262,
ENUM     SDLK_KP7    \ 263,
ENUM     SDLK_KP8    \ 264,
ENUM     SDLK_KP9    \ 265,
ENUM     SDLK_KP_PERIOD    \ 266,
ENUM     SDLK_KP_DIVIDE    \ 267,
ENUM     SDLK_KP_MULTIPLY  \ 268,
ENUM     SDLK_KP_MINUS     \ 269,
ENUM     SDLK_KP_PLUS      \ 270,
ENUM     SDLK_KP_ENTER     \ 271,
ENUM     SDLK_KP_EQUALS    \ 272,

   { Arrows + Home/End pad }
ENUM     SDLK_UP        \ 273,
ENUM     SDLK_DOWN      \ 274,
ENUM     SDLK_RIGHT     \ 275,
ENUM     SDLK_LEFT      \ 276,
ENUM     SDLK_INSERT    \ 277,
ENUM     SDLK_HOME      \ 278,
ENUM     SDLK_END    \ 279,
ENUM     SDLK_PAGEUP    \ 280,
ENUM     SDLK_PAGEDOWN     \ 281,

   { Function keys }
ENUM     SDLK_F1        \ 282,
ENUM     SDLK_F2        \ 283,
ENUM     SDLK_F3        \ 284,
ENUM     SDLK_F4        \ 285,
ENUM     SDLK_F5        \ 286,
ENUM     SDLK_F6        \ 287,
ENUM     SDLK_F7        \ 288,
ENUM     SDLK_F8        \ 289,
ENUM     SDLK_F9        \ 290,
ENUM     SDLK_F10    \ 291,
ENUM     SDLK_F11    \ 292,
ENUM     SDLK_F12    \ 293,
ENUM     SDLK_F13    \ 294,
ENUM     SDLK_F14    \ 295,
ENUM     SDLK_F15    \ 296,
DROP

300
   { Key state modifier keys }
ENUM     SDLK_NUMLOCK      \ 300,
ENUM     SDLK_CAPSLOCK     \ 301,
ENUM     SDLK_SCROLLOCK    \ 302,
ENUM     SDLK_RSHIFT    \ 303,
ENUM     SDLK_LSHIFT    \ 304,
ENUM     SDLK_RCTRL     \ 305,
ENUM     SDLK_LCTRL     \ 306,
ENUM     SDLK_RALT      \ 307,
ENUM     SDLK_LALT      \ 308,
ENUM     SDLK_RMETA     \ 309,
ENUM     SDLK_LMETA     \ 310,
ENUM     SDLK_LSUPER    \ 311,      { Left "Windows" key }
ENUM     SDLK_RSUPER    \ 312,      { Right "Windows" key }
ENUM     SDLK_MODE      \ 313,      { "Alt Gr" key }
ENUM     SDLK_COMPOSE      \ 314,      { Multi-key compose key }

   { Miscellaneous function keys }
ENUM     SDLK_HELP      \ 315,
ENUM     SDLK_PRINT     \ 316,
ENUM     SDLK_SYSREQ    \ 317,
ENUM     SDLK_BREAK     \ 318,
ENUM     SDLK_MENU      \ 319,
ENUM     SDLK_POWER     \ 320,      { Power Macintosh power key }
ENUM     SDLK_EURO      \ 321,      { Some european keyboards }
ENUM     SDLK_UNDO      \ 322,      { Atari keyboard has Undo }
DROP



#define SDL_BUTTON_LEFT    1
#define SDL_BUTTON_MIDDLE  2
#define SDL_BUTTON_RIGHT   3
#define SDL_BUTTON_WHEELUP 4
#define SDL_BUTTON_WHEELDOWN  5

0
ENUM       SDL_NOEVENT           \ Unused (do not remove) */
ENUM       SDL_ACTIVEEVENT       \ Application loses/gains visibility */
ENUM       SDL_KEYDOWN           \ Keys pressed */
ENUM       SDL_KEYUP             \ Keys released */
ENUM       SDL_MOUSEMOTION       \ Mouse moved */
ENUM       SDL_MOUSEBUTTONDOWN   \ Mouse button pressed */
ENUM       SDL_MOUSEBUTTONUP     \ Mouse button released */
ENUM       SDL_JOYAXISMOTION     \ Joystick axis motion */
ENUM       SDL_JOYBALLMOTION     \ Joystick trackball motion */
ENUM       SDL_JOYHATMOTION      \ Joystick hat position change */
ENUM       SDL_JOYBUTTONDOWN     \ Joystick button pressed */
ENUM       SDL_JOYBUTTONUP       \ Joystick button released */
ENUM       _SDL_QUIT              \ User-requested quit */
ENUM       SDL_SYSWMEVENT        \ System specific event */
ENUM       SDL_EVENT_RESERVEDA   \ Reserved for future usep. */
ENUM       SDL_EVENT_RESERVEDB   \ Reserved for future usep. */
ENUM       SDL_VIDEORESIZE       \ User resized video mode */
ENUM       SDL_VIDEOEXPOSE       \ Screen needs to be redrawn */
DROP

#define SDL_QUERY -1
#define SDL_IGNORE    0
#define SDL_DISABLE   0
#define SDL_ENABLE    1

0
enum    SDL_pixelTYPE_UNKNOWN
enum    SDL_pixelTYPE_INDEX1
enum    SDL_pixelTYPE_INDEX4
enum    SDL_pixelTYPE_INDEX8
enum    SDL_pixelTYPE_PACKED8
enum    SDL_pixelTYPE_PACKED16
enum    SDL_pixelTYPE_PACKED32
enum    SDL_pixelTYPE_ARRAYU8
enum    SDL_pixelTYPE_ARRAYU16
enum    SDL_pixelTYPE_ARRAYU32
enum    SDL_pixelTYPE_ARRAYF16
enum    SDL_pixelTYPE_ARRAYF32
drop
0
enum    SDL_BITMAPORDER_NONE
enum    SDL_BITMAPORDER_4321
enum    SDL_BITMAPORDER_1234
drop
0
enum    SDL_PACKEDORDER_NONE
enum    SDL_PACKEDORDER_XRGB
enum    SDL_PACKEDORDER_RGBX
enum    SDL_PACKEDORDER_ARGB
enum    SDL_PACKEDORDER_RGBA
enum    SDL_PACKEDORDER_XBGR
enum    SDL_PACKEDORDER_BGRX
enum    SDL_PACKEDORDER_ABGR
enum    SDL_PACKEDORDER_BGRA
drop
0
enum    SDL_ARRAYORDER_NONE
enum    SDL_ARRAYORDER_RGB
enum    SDL_ARRAYORDER_RGBA
enum    SDL_ARRAYORDER_ARGB
enum    SDL_ARRAYORDER_BGR
enum    SDL_ARRAYORDER_BGRA
enum    SDL_ARRAYORDER_ABGR
drop
0
enum    SDL_PACKEDLAYOUT_NONE
enum    SDL_PACKEDLAYOUT_332
enum    SDL_PACKEDLAYOUT_4444
enum    SDL_PACKEDLAYOUT_1555
enum    SDL_PACKEDLAYOUT_5551
enum    SDL_PACKEDLAYOUT_565
enum    SDL_PACKEDLAYOUT_8888
enum    SDL_PACKEDLAYOUT_2101010
enum    SDL_PACKEDLAYOUT_1010102
drop

{

#define SDL_DEFINE_pixelFOURCC(A, B, C, D) \
    ((A) | ((B) << 8) | ((C) << 16) | ((D) << 24))

#define SDL_DEFINE_pixelFORMAT(type, order, layout, bits, bytes) \
    ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
     ((bits) << 8) | ((bytes) << 0))

#define SDL_pixelTYPE(X)   (((X) >> 24) & 0x0F)
#define SDL_pixelORDER(X)  (((X) >> 20) & 0x0F)
#define SDL_pixelLAYOUT(X) (((X) >> 16) & 0x0F)
#define SDL_BITSPERpixel(X)   (((X) >> 8) & 0xFF)
#define SDL_BYTESPERpixel(X)  (((X) >> 0) & 0xFF)

#define SDL_ISpixelFORMAT_INDEXED(format)   \
    ((SDL_pixelTYPE(format) == SDL_pixelTYPE_INDEX1) || \
     (SDL_pixelTYPE(format) == SDL_pixelTYPE_INDEX4) || \
     (SDL_pixelTYPE(format) == SDL_pixelTYPE_INDEX8))

#define SDL_ISpixelFORMAT_FOURCC(format)    \
    ((format) && !((format) & 0x80000000))
}

{
enum
{
    SDL_pixelFORMAT_UNKNOWN,
    SDL_pixelFORMAT_INDEX1LSB =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
                               1, 0),
    SDL_pixelFORMAT_INDEX1MSB =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
                               1, 0),
    SDL_pixelFORMAT_INDEX4LSB =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
                               2, 0),
    SDL_pixelFORMAT_INDEX4MSB =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
                               2, 0),
    SDL_pixelFORMAT_INDEX8 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_INDEX8, 0, 0, 8, 1),
    SDL_pixelFORMAT_RGB332 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED8, SDL_PACKEDORDER_XRGB,
                               SDL_PACKEDLAYOUT_332, 8, 1),
    SDL_pixelFORMAT_RGB444 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
                               SDL_PACKEDLAYOUT_4444, 12, 2),
    SDL_pixelFORMAT_RGB555 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
                               SDL_PACKEDLAYOUT_1555, 15, 2),
    SDL_pixelFORMAT_BGR555 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
                               SDL_PACKEDLAYOUT_1555, 15, 2),
    SDL_pixelFORMAT_ARGB4444 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
                               SDL_PACKEDLAYOUT_4444, 16, 2),
    SDL_pixelFORMAT_ARGB1555 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
                               SDL_PACKEDLAYOUT_1555, 16, 2),
    SDL_pixelFORMAT_ABGR1555 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
                               SDL_PACKEDLAYOUT_1555, 16, 2),
    SDL_pixelFORMAT_RGB565 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
                               SDL_PACKEDLAYOUT_565, 16, 2),
    SDL_pixelFORMAT_RGB24 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
                               24, 3),
    SDL_pixelFORMAT_BGR24 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0,
                               24, 3),
    SDL_pixelFORMAT_RGB888 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
                               SDL_PACKEDLAYOUT_8888, 24, 4),
    SDL_pixelFORMAT_BGR888 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
                               SDL_PACKEDLAYOUT_8888, 24, 4),
    SDL_pixelFORMAT_ARGB8888 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
                               SDL_PACKEDLAYOUT_8888, 32, 4),
    SDL_pixelFORMAT_RGBA8888 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED32, SDL_PACKEDORDER_RGBA,
                               SDL_PACKEDLAYOUT_8888, 32, 4),
    SDL_pixelFORMAT_ABGR8888 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
                               SDL_PACKEDLAYOUT_8888, 32, 4),
    SDL_pixelFORMAT_BGRA8888 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED32, SDL_PACKEDORDER_BGRA,
                               SDL_PACKEDLAYOUT_8888, 32, 4),
    SDL_pixelFORMAT_ARGB2101010 =
        SDL_DEFINE_pixelFORMAT(SDL_pixelTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
                               SDL_PACKEDLAYOUT_2101010, 32, 4),

    SDL_pixelFORMAT_YV12 =      /* Planar mode: Y + V + U  (3 planes) */
        SDL_DEFINE_pixelFOURCC('Y', 'V', '1', '2'),
    SDL_pixelFORMAT_IYUV =      /* Planar mode: Y + U + V  (3 planes) */
        SDL_DEFINE_pixelFOURCC('I', 'Y', 'U', 'V'),
    SDL_pixelFORMAT_YUY2 =      /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
        SDL_DEFINE_pixelFOURCC('Y', 'U', 'Y', '2'),
    SDL_pixelFORMAT_UYVY =      /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
        SDL_DEFINE_pixelFOURCC('U', 'Y', 'V', 'Y'),
    SDL_pixelFORMAT_YVYU =      /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
        SDL_DEFINE_pixelFOURCC('Y', 'V', 'Y', 'U')
}

{
struct SDL_Palette
{
    int ncolors;
    SDL_Color *colors;

    int refcount;
    SDL_PaletteWatch *watch;
}

{
typedef struct SDL_pixelFormat
{
    SDL_Palette *palette;
    Uint8 BitsPerpixel;
    Uint8 BytesPerpixel;
    Uint8 Rloss;
    Uint8 Gloss;
    Uint8 Bloss;
    Uint8 Aloss;
    Uint8 Rshift;
    Uint8 Gshift;
    Uint8 Bshift;
    Uint8 Ashift;
    Uint32 Rmask;
    Uint32 Gmask;
    Uint32 Bmask;
    Uint32 Amask;
}

\ Function: SDL_SetPaletteColors ( SDL_Palette SDL_Colors-addr firstcolor numcolors -- int )
\ Function: SDL_FreePalette ( SDL_Palette-*palette -- )
\ Function: SDL_AllocPalette ( int-ncolors -- SDL_Palette )

{
typedef struct SDL_Rect
{
    int x, y;
    int w, h;
}


\ Function: SDL_HasIntersection ( recta rectb -- sdl_bool )
\ Function: SDL_IntersectRect ( recta rectb result -- sdl_bool )
\ Function: SDL_UnionRect ( recta rectb result -- )

CFunction: SDL_WM_SetCaption ( caption icon -- )
CFunction: SDL_EnableUNICODE ( flag -- )
1 void cimport: SDL_putenv
1 void cimport: SDL_GetWMInfo
0 cimport: SDL_GetTicks
1 void cimport: SDL_Delay

CFunction: SDL_RWFromFile ( char-*file char-*mode -- rw )
CFunction: SDL_RWFromFP ( FILE-*fp int-autoclose -- rw )
CFunction: SDL_RWFromMem ( void-*mem int-size -- rw )
CFunction: SDL_RWFromConstMem ( void-*mem int-size -- rw )
CFunction: SDL_AllocRW ( void -- addr )
CFunction: SDL_FreeRW ( SDL_RWops-*area -- )
CFunction: SDL_LoadBMP_RW ( RW free-flag -- surface | 0 )
CFunction: SDL_SaveBMP_RW   ( surface RW free-flag -- flag )
CFunction: SDL_SetClipRect  ( surface rect -- )

: SDL_SaveBMP  ( surface filename-z -- flag )
  z" wb" SDL_RWFromFile 1 SDL_SaveBMP_RW ; CSTYLE

: SDL_LoadBMP  ( filename-z -- surface | 0 )
  z" rb" SDL_RWFromFile 1 SDL_LoadBMP_RW ; cstyle


: SDL_BlitSurface   SDL_UpperBlit ; cstyle   \ (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);


{
: >RW   ( addr size -- rw )
   r> -rot SDL_RWFromConstMem  dup >r swap CALL r> SDL_FreeRW ;
}


: sdl-blit
   fourth 0 255 sdl_setalpha
   SDL_BlitSurface ;


include SDL-gfx.f
